package edu.bw.web.user;

import cn.hutool.json.JSONUtil;
import edu.bw.common.CommonResult;
import edu.bw.dto.selectUserByConditionForm;
import edu.bw.service.UserService;
import edu.bw.service.impl.UserServiceImpl;
import edu.bw.utils.PageUtils;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet("/user/selectUserByCondition")
public class SelectUserByConditionServlet extends HttpServlet {
    UserService userService=new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //{page: 1, length: 10, name: "", sex: "", role: "", deptId: "", status: ""}
        String reqJSON = request.getReader().readLine();
        selectUserByConditionForm selectUserByConditionForm = JSONUtil.toBean(reqJSON, selectUserByConditionForm.class);

         PageUtils pageUtils=userService.selectUserByCondition(selectUserByConditionForm);

         response.getWriter().write(JSONUtil.toJsonStr(CommonResult.ok().put("page",pageUtils)));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
